from django.db import models

# Create your models here.
class Category (models.Model):
    name = models.CharField (max_length = 100)
    class Meta:
        verbose_name = '软件分类'
        verbose_name_plural = verbose_name
    
    def __str__ (self):
        return self.name
    
class Tag (models.Model):
    name = models.CharField (max_length = 100)
    class Meta:
        verbose_name = '标签'
        verbose_name_plural = verbose_name
    
    def __str__ (self):
        return self.name

class Atl (models.Model):
    class_name = models.ForeignKey (Category,verbose_name = '软件分类',on_delete = models.CASCADE)
    name = models.CharField ('软件名称',max_length = 100)
    link = models.CharField ('软件链接',max_length = 100)
    down = models.CharField ('下载链接',default= '#',max_length = 200)
    nums = models.PositiveIntegerField (default = 0,editable = False)
    # 注意 views 字段的类型为 PositiveIntegerField，该类型的值只允许为正整数或 0,初始化时 views 的值为 0。将 editable 参数设为 False 将不允许通过 django admin 
    
    class Meta:
        verbose_name = '软件名称'
        verbose_name_plural = verbose_name
        
    def increase_views(self):
        self.nums +=1
        self.save (update_fields = ['nums'])   # 注意这里使用了 update_fields 参数来告诉 Django 只更新数据库中 views 字段的值，以提高效率。
        
    def __str__ (self):
        return self.name 
        
